// This example shows how to get value of multiple OPC properties, and handle errors.
//
// Note that some properties may not have a useful value initially (e.g. until the item is activated in a group), which also the
// case with Timestamp property as implemented by the demo server. This behavior is server-dependent, and normal. You can run
// IEasyDAClient.ReadMultipleItemValues.Main.vbs shortly before this example, in order to obtain better property values. Your
// code may also subscribe to the items in order to assure that they remain active.
using System;
using OpcLabs.BaseLib.OperationModel;
using OpcLabs.EasyOpc;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
partial class GetMultiplePropertyValues
{
public static void Main1()
{
// Instantiate the client object.
var client = new EasyDAClient();
ServerDescriptor serverDescriptor = "OPCLabs.KitServer.2";
// Get the values of Timestamp and AccessRights properties of two items.
ValueResult[] results = client.GetMultiplePropertyValues(new[]
{
new DAPropertyArguments(serverDescriptor, "Simulation.Random", DAPropertyDescriptor.Timestamp),
new DAPropertyArguments(serverDescriptor, "Simulation.Random", DAPropertyDescriptor.AccessRights),
new DAPropertyArguments(serverDescriptor, "Trends.Ramp (1 min)", DAPropertyDescriptor.Timestamp),
new DAPropertyArguments(serverDescriptor, "Trends.Ramp (1 min)", DAPropertyDescriptor.AccessRights)
});
for (int i = 0; i < results.Length; i++)
{
ValueResult valueResult = results[i];
if (valueResult.Exception is null)
Console.WriteLine($"results({i}).Value: {valueResult.Value}");
else
Console.WriteLine($"results({i}).Exception.Message: {valueResult.Exception.Message}");
}
}
}
}
# This example shows how to get value of multiple OPC properties, and handle errors.
#
# Note that some properties may not have a useful value initially (e.g. until the item is activated in a group), which also the
# case with Timestamp property as implemented by the demo server. This behavior is server-dependent, and normal. You can run
# IEasyDAClient.ReadItemValue.Main.vbs shortly before this example, in order to obtain better property values. Your code may
# also subscribe to the item in order to assure that it remains active.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.DataAccess.OperationModel import *
from OpcLabs.EasyOpc.OperationModel import *
serverDescriptor = ServerDescriptor('OPCLabs.KitServer.2')
# Instantiate the client object.
client = EasyDAClient()
# Get the values of Timestamp and AccessRights properties of two items.
resultArray = client.GetMultiplePropertyValues([
DAPropertyArguments(serverDescriptor, DAItemDescriptor('Simulation.Random'), DAPropertyDescriptor.Timestamp),
DAPropertyArguments(serverDescriptor, DAItemDescriptor('Simulation.Random'), DAPropertyDescriptor.AccessRights),
DAPropertyArguments(serverDescriptor, DAItemDescriptor('Trends.Ramp (1 min)'), DAPropertyDescriptor.Timestamp),
DAPropertyArguments(serverDescriptor, DAItemDescriptor('Trends.Ramp (1 min)'), DAPropertyDescriptor.AccessRights),
])
# Display results
for i, valueResult in enumerate(resultArray):
valueResult = resultArray[i]
if valueResult.Exception is None:
print('resultArray[', i, '].Value: ', valueResult.Value, sep='')
else:
print('resultArray[', i, '].Exception.Message: ', valueResult.Exception.Message, sep='')
# This example shows how to get value of multiple OPC properties, and handle errors.
#
# Note that some properties may not have a useful value initially (e.g. until the item is activated in a group), which also the
# case with Timestamp property as implemented by the demo server. This behavior is server-dependent, and normal. You can run
# IEasyDAClient.ReadMultipleItemValues.Main.vbs shortly before this example, in order to obtain better property values. Your
# code may also subscribe to the items in order to assure that they remain active.
#requires -Version 5.1
using namespace OpcLabs.EasyOpc.OperationModel
using namespace OpcLabs.EasyOpc
using namespace OpcLabs.EasyOpc.DataAccess
using namespace OpcLabs.EasyOpc.DataAccess.OperationModel
# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicCore.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassic.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicComponents.dll"
# Instantiate the client object.
$client = New-Object EasyDAClient
$serverDescriptor = New-Object ServerDescriptor("OPCLabs.KitServer.2")
# Get the values of Timestamp and AccessRights properties of two items.
$results = $client.GetMultiplePropertyValues(@(
(New-Object DAPropertyArguments($serverDescriptor, "Simulation.Random", [DAPropertyDescriptor]::Timestamp)),
(New-Object DAPropertyArguments($serverDescriptor, "Simulation.Random", [DAPropertyDescriptor]::AccessRights)),
(New-Object DAPropertyArguments($serverDescriptor, "Trends.Ramp (1 min)", [DAPropertyDescriptor]::Timestamp)),
(New-Object DAPropertyArguments($serverDescriptor, "Trends.Ramp (1 min)", [DAPropertyDescriptor]::AccessRights))
))
for ($i = 0; $i -lt $results.Length; $i++) {
$valueResult = $results[$i]
if ($valueResult.Exception -eq $null) {
Write-Host "results($($i)).Value: $($valueResult.Value)"
}
else {
Write-Host "results($($i)).Exception.Message: $($valueResult.Exception.Message)"
}
}